package top.jingles.sayhiintime;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;

public class NotifyTask
  extends AsyncTask<Void, Void, Void>
{
  private static final int HELLO_ID = 1;
  private Context context;
  private String msgContent;
  private String msgTitle;
  private NotificationManager myNm;
  private Notification notification;
  private Service sv;
  
  public NotifyTask(Context paramContext, Service paramService, NotificationManager paramNotificationManager)
  {
    this.myNm = paramNotificationManager;
    this.sv = paramService;
    this.context = paramContext;
    this.msgTitle = "燕姿说：";
    this.msgContent = "好好工作呀~要注意休息呀~";
  }
  
  protected Void doInBackground(Void... args)
  {
    showNotify();
    try
    {
      Thread.sleep(15000L);
      this.myNm.cancelAll();
    }
    catch (InterruptedException ex)
    {
    }
    return null;
  }
  
  public void setMsgInfo(String msgTitle, String msgContent)
  {
    this.msgTitle = msgTitle;
    this.msgContent = msgContent;
  }
  
  public void showNotify()
  {
    Notification.Builder builder = new Notification.Builder(this.context);
    builder.setSmallIcon(R.drawable.icon); //设置图标
//    builder.setTicker("显示第二个通知");
    builder.setContentTitle(this.msgTitle); //设置标题
    builder.setContentText(this.msgContent); //消息内容
    builder.setWhen(System.currentTimeMillis()); //发送时间
    builder.setDefaults(Notification.DEFAULT_ALL); //设置默认的提示音，振动方式，灯光
    builder.setAutoCancel(true);//打开程序后图标消失
    Intent intent = new Intent(this.sv, SayHiInTimeActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this.sv, 0, intent, 0);
    builder.setContentIntent(pendingIntent);
    this.notification = builder.getNotification();
    this.myNm.notify(1, this.notification); // 通过通知管理器发送通知

//    this.notification = new Notification(R.drawable.icon, this.msgContent, System.currentTimeMillis());
//    String str1 = this.msgTitle;
//    String str2 = this.msgContent;
//    Intent intent = new Intent(this.sv, SayHiInTimeActivity.class);
//    PendingIntent pendingIntent = PendingIntent.getActivity(this.sv, 0, intent, 0);
//    this.notification.setLatestEventInfo(this.context, str1, str2, pendingIntent);
//    this.myNm.notify(1, this.notification);
  }
}
